libxl: remove O_CLOEXEC in xl_cmdimpl.c
authorYongjie Ren <yongjie.ren@intel.com>
Tue, 21 Jun 2011 14:31:34 +0000 (15:31 +0100)
committerYongjie Ren <yongjie.ren@intel.com>
Tue, 21 Jun 2011 14:31:34 +0000 (15:31 +0100)
Some old linux kernels such as 2.6.18 don't define O_CLOEXEC, so
remove O_CLOEXEC in xl_cmdimpl.c and replace with fcntl.

Signed-off-by: Yongjie Ren <yongjie.ren@intel.com>
Committed-by: Ian Jackson <ian.jackson@eu.citrix.com>
tools/libxl/xl_cmdimpl.c

index ecfcac484bcafda92f7525ca9d064c646077c7e9..77f9bc9359c4c6377ede2abde2a04084c9b6e38e 100644 (file)
@@ -199,11 +199,16 @@ static int acquire_lock(void)
     fl.l_whence = SEEK_SET;
     fl.l_start = 0;
     fl.l_len = 0;
-    fd_lock = open(lockfile, O_WRONLY|O_CREAT|O_CLOEXEC, S_IWUSR);
+    fd_lock = open(lockfile, O_WRONLY|O_CREAT, S_IWUSR);
     if (fd_lock < 0) {
         fprintf(stderr, "cannot open the lockfile %s errno=%d\n", lockfile, errno);
         return ERROR_FAIL;
     }
+    if (fcntl(fd_lock, F_SETFD, FD_CLOEXEC) < 0) {
+        close(fd_lock);
+        fprintf(stderr, "cannot set cloexec to lockfile %s errno=%d\n", lockfile, errno);
+        return ERROR_FAIL;
+    }
 get_lock:
     rc = fcntl(fd_lock, F_SETLKW, &fl);
     if (rc < 0 && errno == EINTR)